home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / neuron.zip / SAVENET.C < prev    next >
C/C++ Source or Header  |  1992-07-06  |  3KB  |  109 lines

  1. /* Disk handling module for networks                */
  2. /* TC 2.0    E.FARHI        SAVERES.C            */
  3.  
  4. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    */
  5. /*            VERSION 0.2                */
  6. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  7. /*
  8. version        0.1    01/92    first version
  9.         0.2    05/92    UNIX standard commmands */
  10.  
  11. /* ------------------------------------------------------------    */
  12.  
  13. #include <string.h>     /* for strcpy                          */
  14. #include <stdio.h>    /* disk commands */
  15.  
  16. #define READWRITE 0                     /* for file manip  */
  17. #define AUTOSAVE 1            
  18. #define NORMSAVE 0            
  19. #define AUTOLOAD 1            
  20. #define NORMLOAD 0            
  21.  
  22. /* ------------------------------------------------------------    */
  23.  
  24. int   save_network(NETWORKS *,char);
  25. NETWORKS *load_network(char);
  26.  
  27. int filename(char[]);    /* asks entire name */
  28.  
  29. /* ------------------------------------------------------------ */
  30. /*         File handling                     */
  31. /* ------------------------------------------------------------ */
  32.  
  33. int save_network(NETWORKS *network,char flag)
  34. {       /* if flag=1 saves directly NET00.NET */
  35.   char fname[80];
  36.   FILE *file;
  37.  
  38.   if (flag)
  39.   {
  40.     strcpy(fname,"NET00.NET");
  41.     printf("\nSaving NET00.NET");
  42.   }
  43.   else                          
  44.     filename(fname);   /* file selector */
  45.   file=fopen(fname,"wb");
  46.   if (file == NULL)
  47.     {
  48.       printf("\n\aFile opening error !");
  49.       return(-1);
  50.     }
  51.   else
  52.     {
  53.       printf("\nWriting : %i object transfered",
  54.         fwrite((void *)network,sizeof(NETWORKS),1,file));
  55.       fclose(file);
  56.     }
  57.   return(1);
  58. }
  59.  
  60.  
  61. NETWORKS *load_network(char flag)
  62. {
  63.   FILE *file;
  64.   char fname[80];       /* for file name */
  65.   void *network;
  66.  
  67.   network=(void *)malloc(sizeof(NETWORKS));
  68.   if (network == NULL)    /* is there any room ? */
  69.   {
  70.     printf("Not enough memory. Sorry NetWork too large");
  71.     return(NULL);
  72.   }
  73.  
  74.   if (flag)
  75.   {
  76.     strcpy(fname,"NET00.NET");
  77.     printf("\nLoading file NET00.NET");
  78.   }
  79.   else                        
  80.     filename(fname);   /* file selector */
  81.   file=fopen(fname,"rb");
  82.   if (file == NULL)
  83.     {
  84.       printf("\n\aFile Opening Error !");
  85.       return(NULL);
  86.     }
  87.   else
  88.     {
  89.       printf("\nReading: %i object transfered.",
  90.         fread((void *)network,sizeof(NETWORKS),1,file));
  91.       fclose(file);
  92.     }
  93.   printf("\n <RETURN>");getchar();
  94.   return(network);
  95. }
  96.  
  97. /* -----------------------------------------------------------    */
  98.  
  99. int filename(affichage)
  100.     char affichage[];
  101. {
  102.   char fnam[13];
  103.  
  104.   printf("\nName of file (extension *.NET): ");
  105.   scanf("%s",fnam);
  106.  
  107.   strcpy(affichage,fnam);
  108.   return(1);
  109. }